#include "Server.h"
#include "Service.h"

Server::Server(http_server_t& server) : m_server(server)
{
	m_server.service = &m_router;
	m_server.port = 8989;
	registHandle();
	for (auto& it : m_routers) {
		m_router.AddApi(it.first.c_str(), it.second.first, it.second.second);
	}
	m_router.Static("/", "./html");
}

void Server::start()
{
	http_server_run(&m_server);
}

void Server::registHandle()
{
	m_routers.insert({ "/ping", { HTTP_GET, std::bind(&Service::getPing, &m_service, std::placeholders::_1, std::placeholders::_2) } });
	m_routers.insert({ "/login", { HTTP_POST, std::bind(&Service::postLogin, &m_service, std::placeholders::_1, std::placeholders::_2) } });
	m_routers.insert({ "/getCheck", { HTTP_GET, std::bind(&Service::getCheck, &m_service, std::placeholders::_1, std::placeholders::_2) } });
}
